package com.reny.ll.git.base_logic.api

import com.reny.ll.git.base_logic.api.request.IRequestBodyFactory
import com.reny.ll.git.base_logic.api.request.RequestBodyFactory
import com.reny.ll.git.base_logic.api.request.RequestObj
import okhttp3.RequestBody
import java.io.File

//可以重写 父类方法 自定义的RequestBody工厂
class ReqBodyFactory : RequestBodyFactory() {

    override fun getReq(): RequestObj {
        return RequestObj()
    }

}


object ReqObj{
    val reqBody : IRequestBodyFactory by lazy {
        ReqBodyFactory()
    }
}


fun Any.reqMap(): RequestObj {
    return ReqObj.reqBody.req
}

fun Any.toBody(): RequestBody? {
    return ReqObj.reqBody.build(this)
}

fun Any.toFilesBody(files:List<File>, extraParams: RequestObj? = null): RequestBody?{
    return ReqObj.reqBody.build(extraParams, files)
}

fun File.toFileBody(extraParams: RequestObj? = null): RequestBody?{
    return toFilesBody(listOf(this), extraParams)
}
